package com.itheima.controller;

import com.itheima.domain.Employee;
import com.itheima.service.EmployeeService;
import com.itheima.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @PostMapping("login")
    public R login(@RequestBody Employee employee, HttpSession session) {

        R loginR = employeeService.login(employee);
        if (loginR.getData()!=null)
            session.setAttribute("employee",loginR.getData());
        return loginR;

    }

    @PostMapping("logout")
    public R logout(HttpSession session ) {

        session.invalidate();
        return R.success(null);

    }

}
